package com.mall.business.controller;


import java.util.Arrays;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.mall.common.annotation.Log;
import com.mall.common.core.controller.BaseController;
import com.mall.common.core.domain.AjaxResult;
import com.mall.common.enums.BusinessType;
import com.mall.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mall.business.domain.TPtActive;
import com.mall.business.service.ITPtActiveService;
import com.mall.common.core.page.TableDataInfo;

/**
 * 拼团活动Controller
 *
 * @author ruoyi
 * @date 2025-03-29
 */
@RestController
@RequestMapping("/business/ptactive" )
public class TPtActiveController extends BaseController {
    @Autowired
    private ITPtActiveService tPtActiveService;

/**
 * 查询拼团活动列表
 */
//@RequiresPermissions("business:ptactive:list")
@GetMapping("/list" )
    public TableDataInfo list(TPtActive tPtActive) {
        startPage();
        List<TPtActive> list = tPtActiveService.selectTPtActiveList(tPtActive);
        return getDataTable(list);
    }

    /**
     * 导出拼团活动列表
     */
    //@RequiresPermissions("business:ptactive:export")
    @Log(title = "拼团活动" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, TPtActive tPtActive) {
        List<TPtActive> list = tPtActiveService.selectTPtActiveList(tPtActive);
        ExcelUtil<TPtActive> util = new ExcelUtil<TPtActive>(TPtActive. class);
        util.exportExcel(response, list, "拼团活动数据" );
    }

    /**
     * 获取拼团活动详细信息
     */
    //@RequiresPermissions("business:ptactive:query")
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) String id) {
        return AjaxResult.success(tPtActiveService.selectTPtActiveById(id));
    }

    /**
     * 新增拼团活动
     */
    //@RequiresPermissions("business:ptactive:add")
    @Log(title = "拼团活动" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TPtActive tPtActive) {
        return toAjax(tPtActiveService.save(tPtActive));
    }

    /**
     * 修改拼团活动
     */
    //@RequiresPermissions("business:ptactive:edit")
    @Log(title = "拼团活动" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TPtActive tPtActive) {
        return toAjax(tPtActiveService.updateById(tPtActive));
    }

    /**
     * 删除拼团活动
     */
    //@RequiresPermissions("business:ptactive:remove")
    @Log(title = "拼团活动" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(tPtActiveService.removeByIds(Arrays.asList(ids)));
    }
}
